<?php
/**
 * Created by PhpStorm.
 * User: iceberg
 * Date: 2018-09-12
 * Time: 17:30
 */

namespace app\behavior;


use app\common\SC;
use think\Controller;
use think\facade\Config;
use think\facade\Request;
use think\facade\Session;

class CheckLogin extends Controller
{
    public function run(Request $request){
        // 获取到访问的路径
        $controller = strtolower($request::controller()).'/'.$request::action();
        if (!SC::getLoginSession()) {
            // 排除掉登入的控制器
            if(in_array($controller, Config::get('except.index')) != true){
                // 不存在就验证
                return $this->error('请登录！', url('index/index/login'));
            }
        } else {
            // 登入成功
            if (in_array($controller, Config::get('except.index'))) {
                return $this->redirect(url('index/index/index'));
            }
        }
    }
}